//
//  XYTextAttachment.swift
//  WeiboSourceCode
//
//  Created by 周星宇 on 16/1/9.
//  Copyright © 2016年 cn.weibo. All rights reserved.
//

import UIKit

class XYTextAttachment: NSTextAttachment {
    
    var emoticon: XYEmoticon?
    
    func attrubutedStringWith(emoticion:XYEmoticon ,font:UIFont) -> NSAttributedString {
        
        let image = UIImage(named: emoticion.fullPath, inBundle: XYEmoticonTool.sharedEmoticonTool.emoticonBundle, compatibleWithTraitCollection: nil)
        self.emoticon = emoticion
        self.image = image
        // 调整图片大小
        let imageWH = font.lineHeight
        self.bounds = CGRect(x: 0, y: -3.5, width: imageWH, height: imageWH)
        // 设置附件的大小
        let attr = NSMutableAttributedString(attributedString: NSAttributedString(attachment: self))
        attr.addAttribute(NSFontAttributeName, value:
            font, range: NSMakeRange(0, 1))
        return attr
    }
    
}
